package com.controller;

import com.alibaba.fastjson.JSON;
import com.entity.*;
import com.service.StationService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class StationController {

    @Autowired
    private StationService stationservice;

    @RequestMapping("/getStation")
    public List<Station> getStation(){
        return stationservice.findAll();
    }

    @RequestMapping("/addStation")
    public String addStation(@RequestBody Station station){
        int i=stationservice.addStation(station);
        return i>0?"success":"error";
    }

    @RequestMapping("/deleteStation")
    public String deleteStation(String stnum){
        int i=stationservice.deleteStation(stnum);
        return i > 0 ? "error":"success";
    }

    @RequestMapping("/editStation")
    public String editStation (@RequestBody Station station){
        int i=stationservice.editStation(station);
        return i>0?"success":"error";
    }

    @RequestMapping("/upStation")
    public String upStation(String stnum){
        Station station=stationservice.upStation(stnum);
        String string = JSON.toJSONString(station);
        return string;
    }
}
